package com.ruoyi.recipe.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.recipe.mapper.RecipeArticleMapper;
import com.ruoyi.recipe.domain.RecipeArticle;
import com.ruoyi.recipe.service.IRecipeArticleService;
import com.ruoyi.common.core.text.Convert;

/**
 * 文章Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-14
 */
@Service
public class RecipeArticleServiceImpl implements IRecipeArticleService 
{
    @Autowired
    private RecipeArticleMapper recipeArticleMapper;

    /**
     * 查询文章
     * 
     * @param articleId 文章主键
     * @return 文章
     */
    @Override
    public RecipeArticle selectRecipeArticleByArticleId(Long articleId)
    {
        return recipeArticleMapper.selectRecipeArticleByArticleId(articleId);
    }

    /**
     * 查询文章列表
     * 
     * @param recipeArticle 文章
     * @return 文章
     */
    @Override
    public List<RecipeArticle> selectRecipeArticleList(RecipeArticle recipeArticle)
    {
        return recipeArticleMapper.selectRecipeArticleList(recipeArticle);
    }

    @Override
    public List<RecipeArticle> selectSimpleRecipeArticleList(RecipeArticle recipeArticle) {
        return recipeArticleMapper.selectSimpleRecipeArticleList(recipeArticle);
    }

    /**
     * 新增文章
     * 
     * @param recipeArticle 文章
     * @return 结果
     */
    @Override
    public int insertRecipeArticle(RecipeArticle recipeArticle)
    {
        recipeArticle.setCreateTime(DateUtils.getNowDate());
        return recipeArticleMapper.insertRecipeArticle(recipeArticle);
    }

    /**
     * 修改文章
     * 
     * @param recipeArticle 文章
     * @return 结果
     */
    @Override
    public int updateRecipeArticle(RecipeArticle recipeArticle)
    {
        recipeArticle.setUpdateTime(DateUtils.getNowDate());
        return recipeArticleMapper.updateRecipeArticle(recipeArticle);
    }

    @Override
    public int updateViewsCount(Long[] articleIds, int num) {
        return recipeArticleMapper.updateViewsCount(articleIds, num);
    }

    @Override
    public int updateLikesCount(Long[] articleIds, int num) {
        return recipeArticleMapper.updateLikesCount(articleIds, num);
    }

    /**
     * 批量删除文章
     * 
     * @param articleIds 需要删除的文章主键
     * @return 结果
     */
    @Override
    public int deleteRecipeArticleByArticleIds(String articleIds)
    {
        return recipeArticleMapper.deleteRecipeArticleByArticleIds(Convert.toStrArray(articleIds));
    }

    /**
     * 删除文章信息
     * 
     * @param articleId 文章主键
     * @return 结果
     */
    @Override
    public int deleteRecipeArticleByArticleId(Long articleId)
    {
        return recipeArticleMapper.deleteRecipeArticleByArticleId(articleId);
    }
}
